package udpserver;

import java.io.*;

public class LoadImage{

    
    File fin = null;
    FileInputStream fs = null;
    BufferedInputStream bi = null;
    DataInputStream di =null;

    public LoadImage(String filename) throws IOException{
        
        fin = new File(filename); //hardcoded for now but should get it from outside
        fs = new FileInputStream(fin);
        bi = new BufferedInputStream(fs);
        di = new DataInputStream(bi);
    }
    
    public int readThatByte(byte[] byte_read,int MAX_IO_BUFFER) throws IOException{

        int result;
        result=di.read(byte_read,0,MAX_IO_BUFFER);
        //should i return it ?
        //
        return result;
    }

    public void finishReading() throws IOException{
        if(di!=null)
            di.close();
    }
    public static void main(String[] args){
    

        SaveImage savei = null;
        LoadImage loadi = null;
        int MAX_IO_BUFFER = 4096;
        byte[] byte_array = new byte[MAX_IO_BUFFER];
        
        try{
            savei = new SaveImage();
            loadi = new LoadImage("send.avi");

            
            
            int redMore;

            while((redMore=loadi.readThatByte(byte_array,MAX_IO_BUFFER))!=-1){
                savei.writeThatByte(byte_array,MAX_IO_BUFFER);
            
            }

            savei.finishWriting();
            loadi.finishReading();

                  }
        catch(IOException e){
            System.err.println("IO error occured");
            System.exit(1);
        }
        
        //c++ aliskanliklari insana iyi hissettiriyor!
        savei = null;
        loadi = null;


    }
}
